import asunit.framework.TestCase;

import mockAS2.Stub;
import mockAS2.mocks.ClassToBeMocked;

/**
 * Copyright (c) 2012 Gary Higham
 * Released under the MIT license
 * https://code.google.com/p/mock-as2/wiki/License
 *
 * Version: v0.1
 */
class mockAS2.StubTest extends TestCase {
	private var className : String = "tvpTestFramework.StubTest";
	private var classWithMethod : ClassToBeMocked;
	
	public function StubTest(testMethod : String) {
		super(testMethod);
	}
	
	public function setUp() : Void {
		classWithMethod = new ClassToBeMocked();
	}
	
	public function testAMethodCanBeStubbed() : Void {
		createStub();
		assertEquals("Method has been stubbed to return 2", 2, classWithMethod.return1());
	}
	
	public function testRestoreBringsBackOriginalFunctionality() : Void {
		var stub : Stub = createStub();
		stub.restore();
		assertEquals("Non Stubbed method should return 1", 1, classWithMethod.return1());
	}
	
	private function createStub() : Stub {
		var stubMethod : Function = function() : Number {return 2;};
		return new Stub(classWithMethod, "return1", stubMethod);
	}
}
